package com.reggie.mybatisdemo.mapper;

import com.reggie.mybatisdemo.model.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserInfoMapper {
    //查询所有用户
//    @Select("SELECT * from user_info")
//    @Select("SELECT id, username, password, age, gender, phone, " +
//            "delete_flag deleteFlag, create_time createTime, update_time updateTime" +
//            " from user_info;")
//    @Results(id = "BaseMap", value = {
//            @Result(column = "delete_flag", property = "deleteFlag"),
//            @Result(column = "create_time", property = "createTime"),
//            @Result(column = "update_time", property = "updateTime"),
//    })
    @Select("SELECT * from user_info")
    List<UserInfo> queryAllUser();

    @Select("SELECT * FROM `user_info` WHERE id = 1")
    UserInfo queryById();

    @Select("SELECT * FROM `user_info` WHERE id = #{id}")
    UserInfo queryById1(Integer id);

    @Select("SELECT * FROM `user_info` WHERE id = #{id}")
    List<UserInfo> queryById2(Integer id);

    @Select("select * from `user_info` where username = #{userName} AND `password` = #{password}")
    List<UserInfo> selectByNameAndPassword(String userName, String password);

    @Insert("insert into `user_info`(username, `password`, age) values (#{username},#{password},#{age})")
    Integer insertUser(UserInfo userInfo);

    @Insert("insert into `user_info`(username, `password`, age) values ('${username}','${password}','${age}')")
    Integer insertUser2(UserInfo userInfo);

    @Options(useGeneratedKeys = true , keyProperty = "id")
    @Insert("insert into `user_info`(username, `password`, age) values (#{username},#{password},#{age})")
    Integer insertUser3(UserInfo userInfo);

    @Delete("DELETE FROM `user_info` WHERE id = #{id};")
    Integer deleteById(Integer id);

    @Update("UPDATE user_info SET delete_flag = #{deleteFlag}, phone = #{phone} WHERE id = #{id};")
    Integer updateUser(UserInfo userInfo);

    @Select("SELECT * FROM user_info ORDER BY id ${order};")
    List<UserInfo> selectUserInfoByOrder(String order);

}
